package com.pretty.test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pretty.test.controller.pets.message.dto.MessagePageDTO;
import com.pretty.test.controller.pets.message.vo.MessagePageVO;
import com.pretty.test.controller.pets.message.wrapper.MessagePageWrapper;
import com.pretty.test.entity.PetsMessage;
import com.pretty.test.mapper.PetsMessageMapper;
import com.pretty.test.service.IPetsMessageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pretty.test.utils.otherutils.Func;
import org.springframework.stereotype.Service;

/**
 * 用户反馈服务实现类
 * @author dujianyu
 * @since 2021-04-09
 */
@Service
public class PetsMessageServiceImpl extends ServiceImpl<PetsMessageMapper, PetsMessage> implements IPetsMessageService {

    @Override
    public IPage<MessagePageVO> selectMessagePage(Page<PetsMessage> page, MessagePageDTO dto) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_deleted",0);
        queryWrapper.like(!Func.isBlank(dto.getUserName()),"user_name",dto.getUserName());
        queryWrapper.like(!Func.isBlank(dto.getTheme()),"theme",dto.getTheme());
        queryWrapper.lt(!Func.isEmpty(dto.getCreateTimeEnd()),"create_time",dto.getCreateTimeEnd());
        queryWrapper.gt(!Func.isEmpty(dto.getCreateTimeStart()),"create_time",dto.getCreateTimeStart());
        queryWrapper.orderByDesc("update_time");
        return MessagePageWrapper.build().pageVO(baseMapper.selectPage(page,queryWrapper));
    }
}
